package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.DateTimeEnum;
import com.xbongbong.paas.enums.DefaultTypeEnum;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.paas.field.SubFormPoJo;
import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.pro.enums.PaymentTaskNotifyTypeEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.PaymentTaskDistributorEnum;
import com.xbongbong.saas.enums.dictionary.PaymentTaskStatusEnum;
import com.xbongbong.saas.enums.dictionary.PaymentTypeEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 经销商回款计划初始化枚举
 * @author: zcp
 */
@Getter
public enum TempPaymentTaskDistributorEnum {
    //
    BASE_INFO(PaymentTaskDistributorEnum.BASE_INFO),
    LINK_DISTRIBUTOR(PaymentTaskDistributorEnum.LINK_DISTRIBUTOR),
    LINK_ORDER(PaymentTaskDistributorEnum.LINK_ORDER),
    PAYMENT_TASK_NO(PaymentTaskDistributorEnum.PAYMENT_TASK_NO),
    EXECUTOR(PaymentTaskDistributorEnum.EXECUTOR),
    EXECUTOR_LINKED_TEXT(PaymentTaskDistributorEnum.EXECUTOR_LINKED_TEXT),
    PAYMENT_TASK_NUM(PaymentTaskDistributorEnum.PAYMENT_TASK_NUM),
    EXECUTOR_TIME(PaymentTaskDistributorEnum.EXECUTOR_TIME),
    NOTIFY_TYPE(PaymentTaskDistributorEnum.NOTIFY_TYPE),
    NOTIFY_TIME(PaymentTaskDistributorEnum.NOTIFY_TIME),
    SYSTEM_INFO(PaymentTaskDistributorEnum.SYSTEM_INFO),
    CREATOR_ID(PaymentTaskDistributorEnum.CREATOR_ID),
    ADD_TIME(PaymentTaskDistributorEnum.ADD_TIME),
    UPDATE_TIME(PaymentTaskDistributorEnum.UPDATE_TIME),
    STATUS(PaymentTaskDistributorEnum.STATUS),
    CONTACT_WAY(PaymentTaskDistributorEnum.CONTACT_WAY),
    LINK_DISTRIBUTOR_HIDE(PaymentTaskDistributorEnum.LINK_DISTRIBUTOR_HIDE),
    LINK_ORDER_HIDE(PaymentTaskDistributorEnum.LINK_ORDER_HIDE),
    PAYMENT_TASK_TYPE(PaymentTaskDistributorEnum.PAYMENT_TASK_TYPE),
    MEMO(PaymentTaskDistributorEnum.MEMO)
    ;

    private PaymentTaskDistributorEnum anEnum;

    TempPaymentTaskDistributorEnum(PaymentTaskDistributorEnum anEnum) {
        this.anEnum = anEnum;
    }

    /**
     * 获取所有的枚举码
     *
     * @return
     */
    public static List<TempPaymentTaskDistributorEnum> getAllEnum() {
        List<TempPaymentTaskDistributorEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static void initContactWay(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity item = InitExplainsHelper.setField(StringConstant.PLAN_CONTACT_ATTR, "联系人", "contact", FieldTypeEnum.TEXT.getType(), 4, ShowTypeEnum.DETAIL.getCode(), 0, 1);
        items.add(item);
        FieldAttrEntity item2 = InitExplainsHelper.setField(StringConstant.PLAN_PHONE_ATTR, "联系方式", "phone", FieldTypeEnum.TEXT.getType(), 4, ShowTypeEnum.DETAIL.getCode(), 0, 1);
        items.add(item2);
        FieldAttrEntity item3 = InitExplainsHelper.setField(StringConstant.PLAN_ADDRESS_ATTR, "地址", "address", FieldTypeEnum.TEXT.getType(), 4, ShowTypeEnum.DETAIL.getCode(), 0, 1);
        items.add(item3);
        subFormPoJo.setItems(items);
        fieldAttrEntity.setSubForm(subFormPoJo);
    }

    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    /**
     * 初始化执行人
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initExecutor(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        ItemPoJo itemPoJo1 = new ItemPoJo();
        itemPoJo1.setText("负责人");
        itemPoJo1.setValue("0");
        itemPoJo1.setChecked(true);
        itemPoJos.add(itemPoJo1);
        ItemPoJo itemPoJo2 = new ItemPoJo();
        itemPoJo2.setText("协同人");
        itemPoJo2.setValue("1");
        itemPoJo2.setChecked(false);
        itemPoJos.add(itemPoJo2);
        ItemPoJo itemPoJo3 = new ItemPoJo();
        itemPoJo3.setText("自定义");
        itemPoJo3.setValue("2");
        itemPoJo3.setChecked(false);
        List<String> fieldMap = new ArrayList<>();
        fieldMap.add(EXECUTOR_LINKED_TEXT.anEnum.getAttr());
        itemPoJo3.setFieldMap(fieldMap);
        itemPoJos.add(itemPoJo3);
        fieldAttrEntity.setItems(itemPoJos);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType("custom");
        defaultAttrPoJo.setDefaultValue("");
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
    }

    public static void initExecutorLinkedText(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
    }

    public static void initPaymentTaskNo(FieldAttrEntity fieldAttrEntity){
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.PAYMENT_TASK.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.PAYMENT_TASK.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(PAYMENT_TASK_NO.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setNoRepeat(1);
        fieldAttrEntity.setSerialNumber(InitExplainsHelper.setSerialNumber(SerialNumberEnum.PAYMENT_TASK_NO));
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowAttrPermission(BasicConstant.ZERO);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
    }

    /**
     * 初始化关联客户
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initLinkDistributor(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.CUSTOMER.getCode());
        fieldAttrEntity.setLinkedText(LINK_DISTRIBUTOR_HIDE.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setRelyBusiness(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
    }

    /**
     * 初始化关联合同
     *
     * @param fieldAttrEntity
     */
    public static void initLinkOrder(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.CONTRACT.getCode());
        fieldAttrEntity.setLinkedText(LINK_ORDER_HIDE.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        saasParticularAttributePoJo.setRelyAttr(LINK_DISTRIBUTOR.anEnum.getAttr());
        saasParticularAttributePoJo.setRelyBusiness(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
    }

    /**
     * 初始化提醒字段
     *
     * @param fieldAttrEntity
     */
    public static void initNotifyType(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        ItemPoJo itemPoJo1 = new ItemPoJo();
        itemPoJo1.setText(PaymentTaskNotifyTypeEnum.NO_NOTIFY.getAlias());
        itemPoJo1.setValue(PaymentTaskNotifyTypeEnum.NO_NOTIFY.getCode().toString());
        itemPoJo1.setChecked(true);
        itemPoJos.add(itemPoJo1);
        ItemPoJo itemPoJo2 = new ItemPoJo();
        itemPoJo2.setText(PaymentTaskNotifyTypeEnum.ADVANCE_ONE_QUARTER_HOUR.getAlias());
        itemPoJo2.setValue(PaymentTaskNotifyTypeEnum.ADVANCE_ONE_QUARTER_HOUR.getCode().toString());
        itemPoJo2.setChecked(false);
        itemPoJos.add(itemPoJo2);
        ItemPoJo itemPoJo3 = new ItemPoJo();
        itemPoJo3.setText(PaymentTaskNotifyTypeEnum.ADVANCE_ONE_HOUR.getAlias());
        itemPoJo3.setValue(PaymentTaskNotifyTypeEnum.ADVANCE_ONE_HOUR.getCode().toString());
        itemPoJo3.setChecked(false);
        itemPoJos.add(itemPoJo3);
        ItemPoJo itemPoJo4 = new ItemPoJo();
        itemPoJo4.setText(PaymentTaskNotifyTypeEnum.ADVANCE_ONE_DAY.getAlias());
        itemPoJo4.setValue(PaymentTaskNotifyTypeEnum.ADVANCE_ONE_DAY.getCode().toString());
        itemPoJo4.setChecked(false);
        itemPoJos.add(itemPoJo4);
        ItemPoJo itemPoJo5 = new ItemPoJo();
        itemPoJo5.setText(PaymentTaskNotifyTypeEnum.ADVANCE_THREE_DAY.getAlias());
        itemPoJo5.setValue(PaymentTaskNotifyTypeEnum.ADVANCE_THREE_DAY.getCode().toString());
        itemPoJo5.setChecked(false);
        itemPoJos.add(itemPoJo5);
        ItemPoJo itemPoJo6 = new ItemPoJo();
        itemPoJo6.setText(PaymentTaskNotifyTypeEnum.ADVANCE_ONE_WEEK.getAlias());
        itemPoJo6.setValue(PaymentTaskNotifyTypeEnum.ADVANCE_ONE_WEEK.getCode().toString());
        itemPoJo6.setChecked(false);
        itemPoJos.add(itemPoJo6);
        ItemPoJo itemPoJo7 = new ItemPoJo();
        itemPoJo7.setText(PaymentTaskNotifyTypeEnum.CUSTOM_TIME.getAlias());
        itemPoJo7.setValue(PaymentTaskNotifyTypeEnum.CUSTOM_TIME.getCode().toString());
        itemPoJo7.setChecked(false);

        List<String> fieldMap = new ArrayList<>();
        fieldMap.add(NOTIFY_TIME.anEnum.getAttr());
        itemPoJo7.setFieldMap(fieldMap);
        itemPoJos.add(itemPoJo7);
        fieldAttrEntity.setItems(itemPoJos);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType("custom");
        defaultAttrPoJo.setDefaultValue("");
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setIsForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
    }

    /**
     * 初始化提醒时间
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initNotifyTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType("yyyy-MM-dd HH:mm");
        fieldAttrEntity.setIsForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
    }

    /**
     * 初始化回款计划状态
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initStatus(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(PaymentTaskStatusEnum.class, fieldAttrEntity.getFieldType(),"alias",null));
    }
    /**
     * 初始化回款类型
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initPaymentTaskType(FieldAttrEntity fieldAttrEntity) {
//        String str = "常规,预收款,尾款,保证金,回款支付";
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(PaymentTypeEnum.class, fieldAttrEntity.getFieldType()));
        fieldAttrEntity.setDictionaryFlag(1);
    }

    /**
     * 初始化计划收款金额
     *
     * @param fieldAttrEntity
     */
    public static void initPaymentTaskNum(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
        fieldAttrEntity.setNumericalLimitsFlag(BasicConstant.ONE);
    }

    public static void initExecutorTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType( DateTimeEnum.DATETIME.getType());
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.TODAY.getAlias());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
    }
}
